package leetcode_1101_1200;

import java.util.*;

public class LeeCode_1124 {
    public static void main(String[] args) {

    }
    private static int longestWPI(int[] hours) {
        int n = hours.length;
        Map<Integer, Integer> map = new HashMap<>();
        int s = 0, ans = 0;
        for (int i = 0; i < n; i++) {
            s += hours[i] > 8 ? 1 : -1;
            if (s > 0){
                ans = Math.max(ans, i + 1);
            }else {
                if (map.containsKey(s - 1)){
                    ans = Math.max(ans, i - map.get(s - 1));
                }
            }
            if (s < 0 && !map.containsKey(s)){
                map.put(s, i);
            }
        }
        return ans;
    }
}